package cn.stylefeng.guns.sys.modular.rest.controller;

import cn.hutool.core.util.ObjectUtil;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.core.util.LogUtil;
import cn.stylefeng.guns.sys.modular.rest.entity.NameRelation;
import cn.stylefeng.guns.sys.modular.rest.model.params.NameRelationParam;
import cn.stylefeng.guns.sys.modular.rest.model.result.NameRelationResult;
import cn.stylefeng.guns.sys.modular.rest.service.NameRelationService;
import cn.stylefeng.roses.core.base.controller.BaseController;
//import cn.stylefeng.roses.kernel.model.response.ResponseData;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * 控制器
 *
 * @author huylei
 * @Date 2022-05-18 17:47:13
 */
@Controller
@RequestMapping("/btyNameRelation")
public class NameRelationController extends BaseController {

    private String PREFIX = "/modular/system/btyNameRelation";

    @Autowired
    private NameRelationService nameRelationService;


    //@Scheduled(cron = "*/5 * * * * ?")
 /*   @RequestMapping("/updataList")
    public void updataList() {
        LogUtil logUtil=new LogUtil();
        //List<NameRelation> list=new ArrayList();
        List<Map<String, String>> store = logUtil.getStore();
        for (int i = 0; i <store.size() ; i++) {
            //判断scm_code是否为空
            if (ObjectUtil.isNotEmpty(store.get(i).get("scmCode"))&& !store.get(i).get("scmCode").equals("\"\"")){
            //查询是否有此条数据
            NameRelation scmCode = nameRelationService.findByScmCode(store.get(i).get("scmCode"));
            if (ObjectUtil.isNotEmpty(scmCode)){
                //有数据调用更新接口
                nameRelationService.updateByScmCode(scmCode);
            }else {
                //没有则添加
                NameRelationParam btyNameRelation=new NameRelationParam();
                btyNameRelation.setShopCode(store.get(i).get("shopCode"));
                btyNameRelation.setScmCode(store.get(i).get("scmCode"));
                btyNameRelation.setScmName(store.get(i).get("scmName"));
                //list.add(btyNameRelation);
                nameRelationService.add(btyNameRelation);
            }
        }  }
        //this.nameRelationService.addListAll(list);
    }*/


    /**
     * 跳转到主页面
     *
     * @author huylei
     * @Date 2022-05-18
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/btyNameRelation.html";
    }

    /**
     * 新增页面
     *
     * @author huylei
     * @Date 2022-05-18
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/nameRelation_add.html";
    }

    /**
     * 编辑页面
     *
     * @author huylei
     * @Date 2022-05-18
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/nameRelation_edit.html";
    }

 /*   *//**
     * 新增接口
     *
     * @author huylei
     * @Date 2022-05-18
     *//*
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(NameRelationParam nameRelationParam) {
        this.nameRelationService.add(nameRelationParam);
        return ResponseData.success();
    }

    *//**
     * 编辑接口
     *
     * @author huylei
     * @Date 2022-05-18
     *//*
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(NameRelationParam nameRelationParam) {
        this.nameRelationService.update(nameRelationParam);
        return ResponseData.success();
    }

    *//**
     * 删除接口
     *
     * @author huylei
     * @Date 2022-05-18
     *//*
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(NameRelationParam nameRelationParam) {
        this.nameRelationService.delete(nameRelationParam);
        return ResponseData.success();
    }

    *//**
     * 查看详情接口
     *
     * @author huylei
     * @Date 2022-05-18
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(NameRelationParam nameRelationParam) {
        NameRelation detail = this.nameRelationService.findByShopCode(nameRelationParam.getShopCode());
         //this.nameRelationService.getById(nameRelationParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author huylei
     * @Date 2022-05-18
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(NameRelationParam nameRelationParam) {
        return this.nameRelationService.findPageBySpec(nameRelationParam);
    }

}


